package com.kvest.testtask.android;

import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class SiteOverlay extends ItemizedOverlay<OverlayItem>
{
	private List<OverlayItem> sites = new ArrayList<OverlayItem>();
	private TapListener tapListener;
	
	public SiteOverlay(Drawable marker) 
	{
		  super(boundCenterBottom(marker));
		  
		  tapListener = null;
	}
	
	@Override
	protected boolean onTap(int index) 
	{
		//emit event for listener
		if (tapListener != null)
		{
			tapListener.tapAction(sites.get(index).getPoint());
		}
		
		return true;
	}
	
	@Override
	protected OverlayItem createItem(int i)
	{
		return sites.get(i);
	}
	
	@Override
	public int size()
	{
		return sites.size();
	}
	
	public void addOverlayItem(OverlayItem site) 
	{
		sites.add(site);
	    populate();
	}
	
	public void setTapListener(TapListener tapListener)
	{
		this.tapListener = tapListener;
	}
	
	public interface TapListener
	{
		public void tapAction(GeoPoint point);
	}
}
